package com.amikomgamedev.panjatpinang.states;

import org.andengine.engine.camera.Camera;
import org.andengine.engine.handler.timer.ITimerCallback;
import org.andengine.engine.handler.timer.TimerHandler;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.text.Text;
import org.andengine.opengl.font.Font;
import org.andengine.opengl.font.FontFactory;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.ui.activity.SimpleBaseGameActivity;
import org.andengine.util.HorizontalAlign;

import android.content.Intent;
import android.graphics.Color;

import com.amikomgamedev.panjatpinang.Data;
import com.amikomgamedev.panjatpinang.Data_Credits;
import com.amikomgamedev.panjatpinang.Define;

/*
 * AndEngineGamePanjatPinang
 * State_Ucapan.java
 * Pratama Wijaya
 * set.mnemonix@gmail.com
 * 12:52:33 AM , Aug 11, 2012
 */

public class State_Ucapan extends SimpleBaseGameActivity implements Data,
		Define, Data_Credits {
	private Scene	mScene;
	private Camera	mCamera;

	private BitmapTextureAtlas	texFont, texBg;
	private ITextureRegion		treBg;
	private Sprite				sprBg;
	private Font				font;
	private Text				ucapan;

	@Override
	public EngineOptions onCreateEngineOptions() {
		// TODO Auto-generated method stub
		mCamera = new Camera(0, 0, GAME_SCREEN_WIDTH, GAME_SCREEN_HEIGHT);
		EngineOptions en = new EngineOptions(true,
				ScreenOrientation.PORTRAIT_FIXED, new RatioResolutionPolicy(
						GAME_SCREEN_WIDTH, GAME_SCREEN_HEIGHT), mCamera);

		return en;
	}

	@Override
	protected void onCreateResources() {
		// TODO Auto-generated method stub
		texBg = new BitmapTextureAtlas(this.getTextureManager(), 512, 512,
				TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		treBg = BitmapTextureAtlasTextureRegionFactory.createFromAsset(texBg,
				this.getAssets(), IMG_TEMPAT_TULISAN, 0, 0);

		texFont = new BitmapTextureAtlas(this.getTextureManager(), 256, 256,
				TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		font = FontFactory.createFromAsset(this.getFontManager(), texFont,
				this.getAssets(), FONT_STYLE, 16, true, Color.BLACK);
		texBg.load();
		font.load();

	}

	@Override
	protected Scene onCreateScene() {
		// TODO Auto-generated method stub
		mScene = new Scene();
		mScene.setBackground(new Background(
				org.andengine.util.color.Color.WHITE));
		sprBg = new Sprite(0, 0, treBg, mEngine.getVertexBufferObjectManager());
		sprBg.setPosition((GAME_SCREEN_WIDTH >> 1) - sprBg.getWidth() / 2, 0);

		ucapan = new Text(0, 0, font, TXT_UCAPAN,
				mEngine.getVertexBufferObjectManager());
		
		ucapan.setPosition((GAME_SCREEN_WIDTH >> 1) - ucapan.getWidth() / 2,
				(GAME_SCREEN_HEIGHT >> 1) - ucapan.getHeight() / 2);
		
		ucapan.setHorizontalAlign(HorizontalAlign.CENTER);

		mScene.attachChild(sprBg);
		mScene.getLastChild().attachChild(ucapan);

		mEngine.registerUpdateHandler(new TimerHandler(4f,
				new ITimerCallback() {

					@Override
					public void onTimePassed(TimerHandler pTimerHandler) {
						// TODO Auto-generated method stub
						Intent menu = new Intent(State_Ucapan.this,
								State_MainMenu.class);
						startActivity(menu);
						finish();

					}
				}));

		return mScene;
	}
}
